home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / pbclon21.zip / PATCHER.BAS < prev    next >
BASIC Source File  |  1993-01-11  |  2KB  |  53 lines

  1. '   +----------------------------------------------------------------------+
  2. '   |                                                                      |
  3. '   |        PBClone  Copyright (c) 1990-1993  Thomas G. Hanlin III        |
  4. '   |                                                                      |
  5. '   +----------------------------------------------------------------------+
  6.  
  7. '  NOTE: Do not LINK with the /E (/EXEPACK) switch.
  8.  
  9.    DECLARE SUB FindPatch (FileName$, SearchSt$, ErrCode%)
  10.    DECLARE SUB SetPatch (St$)
  11.    DECLARE SUB PatchDone ()
  12.  
  13.    DEFINT A-Z
  14.  
  15.    ' --- We read SearchSt$ to avoid duplicating it in an assignment statement.
  16.    ' --- The ConfigSt$ is the value we patched in last time.
  17.    READ SearchSt$, ConfigSt$
  18.  
  19.    ' --- Get the value to patch in this time.
  20.    St$ = LTRIM$(RTRIM$(COMMAND$))
  21.  
  22.    ' --- Make it the right length (this is important)!
  23.    IF LEN(St$) < LEN(ConfigSt$) THEN
  24.       St$ = St$ + SPACE$(LEN(ConfigSt$) - LEN(St$))
  25.    ELSE
  26.       St$ = LEFT$(St$, LEN(ConfigSt$))
  27.    END IF
  28.  
  29.    ' --- Tell 'em what's up.
  30.    PRINT "This is a demo of the PBClone routines which allow a program to patch itself."
  31.    PRINT "It patches itself with whatever you enter on the command line."
  32.    PRINT
  33.    PRINT "The last entry was: "; CHR$(34); RTRIM$(ConfigSt$); CHR$(34)
  34.    PRINT "Next time it'll be: "; CHR$(34); RTRIM$(St$); CHR$(34)
  35.  
  36.    ' --- Here we do the actual patching.
  37.    ' --- Note that the ".EXE" extension is optional.
  38.    FindPatch "PATCHER", SearchSt$, ErrCode
  39.    IF ErrCode THEN
  40.       PRINT "Unable to patch PATCHER.EXE-- error code: "; ErrCode
  41.       END
  42.    END IF
  43.    SetPatch St$
  44.    PatchDone
  45.  
  46.    ' --- Here's the data: one quoted string per statement, with the first
  47.    ' --- statement containing a unique string.  The first statement won't be
  48.    ' --- patched, since we may need it again another time.  The second data
  49.    ' --- statement will be the first patched.  There is no limit to the
  50.    ' --- number of data statements which may be patched.
  51.    DATA "UniqueString"
  52.    DATA "This space intentionally left blank!                             "
  53.